/**
 * 保存 立即购买 的参数
 */
import md5 from 'js-md5'
import * as cache from '../../util/cache'

const paramsKey = 'sbsb' + md5('order')

export default {
  namespaced: true,
  state: {
    params: {},
    // 解决技术论坛对应分类
    materialId: null
  },
  getters: {
    // params: state => state.params,
    params: state => {
      if (Object.keys(state.params).length === 0) {
        state.params = cache.get(paramsKey)
      }
      return state.params
    },
    materialId: state => state.materialId
  },
  mutations: {
    SET_PARAMS: (state, params) => {
      state.params = params
      cache.save(paramsKey, params)
    },
    SET_MATERIAL_ID: (state, id) => {
      state.materialId = id
    }
  },
  actions: {
    set_params: ({ commit }, params) => {
      commit('SET_PARAMS', params)
    },
    set_material: ({ commit }, id) => {
      commit('SET_MATERIAL_ID', id)
    }
  }
}
